<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

/**
* This controller is used for JAEmail feature of the component
*/
class JAJobBoardControllerJACodes extends JAJobBoardController {
/**
     * Constructor
     */
    function __construct( $location = array() )
    {
    	
        parent::__construct( $location );      
        // Register Extra tasks
        $this->registerTask( 'add',     'edit' );
    }
    
    /**
    * Display current jacodes of the component to administrator
    * 
    */
    function display(){
    	/*$db = JFactory::getDBO();
    	$sql = "select c.id, c.field_id, f.table_name, f.field_name from #__ja_codes as c inner join #__ja_form_fields as f where c.field_id=f.id";
    	$db->setQuery($sql);
    	
    	$list = $db->loadObjectList();
    	
    	foreach ($list as $row){
    		$field = $row->table_name.'_'.$row->field_name;
    		$query = "update #__ja_codes  set field_id='$field' where id='{$row->id}'";
    		$db->setQuery($query);    	
    		$db->query();    		
    	}*/
    	
		parent::display();
    }
    
    /**
    * Cancel current operation
    * 
    */
    function cancel(){
    	global $option;
        $this->setRedirect("index.php?option=$option&view=jacodes");
    }   
    /**
    * Remove a jacodes row
    * 
    */   
    function remove(){
    	global $option;
 
    	// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
        
        $model =& $this->getModel('jacodes');

        if(($n = $model->remove()) < 0){
             JError::raiseWarning( 500, $row->getError() );
		}
		$field_id = JRequest::getVar('field_id', 0);
		$this->setRedirect( "index.php?option=$option&view=jacodes&tmpl=component&field_id=$field_id" , $msg );
	}
	
	
	/**
	* Save categories record
	*/
	function save(){
		global $option;
		
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
		
		$cache = & JFactory::getCache($option);
		$cache->clean();

		$model	=& $this->getModel('jacodes');
		$post	= JRequest::get('post');
			
		$model->setState( 'request', $post );
		
		$field_id = JRequest::getVar('field_id', '');
		
		if ($id = $model->store()) {
			$msg = JText::_( 'The option item Saved' );
		} else {
			$msg = JText::_('Please enter value and text');
		}
		
		$this->setRedirect( "index.php?option=$option&view=jacodes&tmpl=component&field_id=$field_id" , $msg );
	}			
}